<?php
    @include_once("conn.php");
    @include_once("common.php");    

    $user = $_GET["user"];

    // if(!$user){
    //     argErr();
    // }

    //  执行查询语句  => 结果对象
    $search = "select s.id,s.user,s.goodsId,s.buyNum,x.goodsId,x.goodsName,x.goodsPrice,x.goodsImg from `shoppingcar` as s,`xm` as x where s.goodsId = x.goodsId and s.user ='$user'";
    
   
    // $search = "select s.id,s.user,s.goodsId,s.buyNum,xm.goodsName,xm.goodsPrice,xm.goodsImg,round(s.buyNum*xm.goodsPrice,2) as subTotal from `shoppingcar` as s,`xm` as g where s.goodsId = xm.goodsId and s.user ='$user'";
    $result = mysqli_query($conn,$search);
    // print_r($result);

    // 多数据查询   循环解析,每次解析之后 将数据放到总的集合中
    $all = array();
    while($item = mysqli_fetch_assoc($result)){   // 解析传入的结果对象 赋值给变量$item , 解析成功 有数据 => true 下次继续解析,  解析失败(没有数据 =>false  跳出循环) 

        $item["goodsImg"] = explode(",",$item["goodsImg"] );
        $item["goodsImg"] = $item["goodsImg"][0];

        array_push($all,$item); 
    }
//    print_r($all);
    // $msg = array();
    // if(count($all)>0){

    
    //     $msg["status"] = true;
    //     $msg["detail"] = "ok";
    //     $msg["data"] = $item;
    // }else{
    //     $msg["status"] = false;
    //     $msg["detail"] = "false";
    //     $msg["sql"] = $search;
        
    // }

    echo json_encode($all);  // 将数据转为json类型的字符串  并输出

?>